package com.itheima.dubbo.mysql.impl;


import cn.hutool.core.util.StrUtil;
import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.commons.model.domain.Admin;
import com.itheima.commons.model.domain.Announcement;
import com.itheima.dubbo.interfaces.AdminApi;
import com.itheima.dubbo.interfaces.AnnouncementApi;
import com.itheima.dubbo.mysql.mapper.AdminMapper;
import com.itheima.dubbo.mysql.mapper.AnnouncementUserMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class AdminApiImpl implements AdminApi {

    @Autowired
    private AdminMapper adminMapper;


    @Override
    public Admin queryWithId(Long adminId) {
        return adminMapper.selectOne(Wrappers.lambdaQuery(Admin.class).eq(Admin::getAdminId, adminId));
    }

    /**
     * 通过管理员姓名模糊查询管理员集合
     *
     * @param adminName
     * @return
     */
    @Override
    public List<Admin> queryByName(String adminName) {
        List<Admin> admins = adminMapper.selectList(Wrappers.lambdaQuery(Admin.class)
                .like(StrUtil.isNotBlank(adminName), Admin::getUsername, adminName));
        return admins;
    }
}
